/*  
 * Actipro Software's WPF Docking & MDI / Prism Integration Add-on
 * http://actipro.codeplex.com/
 * 
 * Copyright (c) 2009-2015 Actipro Software LLC. 
 *  
 * This source code is subject to the terms of the Microsoft Public License (Ms-PL). 
 *  
 * Redistribution and use in source and binary forms, with or without modification, 
 * is permitted provided that redistributions of the source code retain the above 
 * copyright notices and this file header. 
 *  
 * Additional copyright notices should be appended to the list above. 
 * 
 * For details, see <http://www.opensource.org/licenses/ms-pl.html>. 
 *  
 * All other rights reserved. 
 *
 */  

using System;
using System.Windows;
using System.Windows.Media;
using ActiproSoftware.Windows.Controls.Docking;

namespace ActiproSoftware.Windows.Prism.Regions {

	/// <summary>
	/// Represents an implementation of <see cref="IDockingWindowInitializer"/> for document items.
	/// </summary>
	public class DocumentWindowInitializer : DockingWindowInitializer {

		#region Dependency Properties

		/// <summary>
		/// Identifies the <see cref="CanEditTitle"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="CanEditTitle"/> dependency property.</value>
		public static readonly DependencyProperty CanEditTitleProperty = DependencyProperty.Register("CanEditTitle",
			typeof(bool?), typeof(DocumentWindowInitializer), new FrameworkPropertyMetadata(null));

		/// <summary>
		/// Identifies the <see cref="FileName"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="FileName"/> dependency property.</value>
		public static readonly DependencyProperty FileNameProperty = DependencyProperty.Register("FileName",
			typeof(string), typeof(DocumentWindowInitializer), new FrameworkPropertyMetadata(null));

		/// <summary>
		/// Identifies the <see cref="IsReadOnly"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="IsReadOnly"/> dependency property.</value>
		public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly",
			typeof(bool), typeof(DocumentWindowInitializer), new FrameworkPropertyMetadata(false));

		/// <summary>
		/// Identifies the <see cref="ReadOnlyContextImageSource"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="ReadOnlyContextImageSource"/> dependency property.</value>
		public static readonly DependencyProperty ReadOnlyContextImageSourceProperty = DependencyProperty.Register("ReadOnlyContextImageSource",
			typeof(ImageSource), typeof(DocumentWindowInitializer), new FrameworkPropertyMetadata(null));

		#endregion // Dependency Properties

		/////////////////////////////////////////////////////////////////////////////////////////////////////
		#region PUBLIC PROCEDURES
		/////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// Gets or sets whether the end user can edit the associated window's title in-place when its tab is double-clicked.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// A nullable <see cref="Boolean"/> that indicates whether the end user can edit the associated window's title in-place.
		/// The default value is <see langword="null"/>.
		/// </value>
		/// <remarks>
		/// If set to <see langword="null"/>, the resolved value will use the global <see cref="DockSite"/> setting.
		/// </remarks>
		public bool? CanEditTitle {
			get { return (bool?)this.GetValue(CanEditTitleProperty); }
			set { this.SetValue(CanEditTitleProperty, value); }
		}

		/// <summary>
		/// Creates a new instance of the <see cref="DocumentWindowInitializer"/> class.
		/// </summary>
		/// <returns>The new instance.</returns>
		protected override Freezable CreateInstanceCore() {
			return new DocumentWindowInitializer();
		}

		/// <summary>
		/// Gets or sets the full path to the document for the associated docking window.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// The full path to the document.
		/// The default value is <see langword="null"/>.
		/// </value>
		/// <remarks>
		/// This property is displayed on switchers.
		/// </remarks>
		[Localizability(LocalizationCategory.NeverLocalize)]
		public string FileName {
			get { return (string)this.GetValue(FileNameProperty); }
			set { this.SetValue(FileNameProperty, value); }
		}

		/// <summary>
		/// Gets the docking window item type of the specified item.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns>
		/// A <see cref="DockingWindowItemType"/> value.
		/// </returns>
		public override DockingWindowItemType GetDockingWindowItemType(object item) {
			return DockingWindowItemType.Document;
		}

		/// <summary>
		/// Initializes the specified docking window with any associated metadata.
		/// </summary>
		/// <param name="dockingWindow">The docking window that should be initialized.</param>
		/// <param name="item">The associated item.</param>
		public override void Initialize(DockingWindow dockingWindow, object item) {
			// Call base method
			base.Initialize(dockingWindow, item);

			DocumentWindow documentWindow = dockingWindow as DocumentWindow;
			if (documentWindow != null) {
				this.BindProperty(CanEditTitleProperty, documentWindow, DocumentWindow.CanEditTitleProperty);
				this.BindProperty(FileNameProperty, documentWindow, DocumentWindow.FileNameProperty);
				this.BindProperty(IsReadOnlyProperty, documentWindow, DocumentWindow.IsReadOnlyProperty);
				this.BindProperty(ReadOnlyContextImageSourceProperty, documentWindow, DocumentWindow.ReadOnlyContextImageSourceProperty);
			}
		}

		/// <summary>
		/// Gets or sets whether the associated document window is currently in a read-only state.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// <c>true</c> if the associated document window is currently in a read-only state; otherwise, <c>false</c>.
		/// The default value is <c>false</c>.
		/// </value>
		/// <remarks>
		/// When set to <c>true</c> the <see cref="ReadOnlyContextImageSource"/> property value will be set to
		/// the <see cref="DockingWindow.ContextImageSource"/> property.
		/// </remarks>
		public bool IsReadOnly {
			get { return (bool)this.GetValue(IsReadOnlyProperty); }
			set { this.SetValue(IsReadOnlyProperty, value); }
		}

		/// <summary>
		/// Gets or sets the <see cref="System.Windows.Media.ImageSource"/> to set to the <see cref="DockingWindow.ContextImageSource"/>
		/// property when the <see cref="IsReadOnly"/> property is set to <c>true</c> for the associated docking window.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// The <see cref="System.Windows.Media.ImageSource"/> to set to the <see cref="DockingWindow.ContextImageSource"/>
		/// property when the <see cref="IsReadOnly"/> property is set to <c>true</c>.
		/// The default value is <see langword="null"/>.
		/// </value>
		public ImageSource ReadOnlyContextImageSource {
			get { return (ImageSource)this.GetValue(ReadOnlyContextImageSourceProperty); }
			set { this.SetValue(ReadOnlyContextImageSourceProperty, value); }
		}

		#endregion // PUBLIC PROCEDURES
	}
}